<?php
if (! defined ( 'IN_BIC' )) {
	die ( '非法Controller访问来源!' );
}
/**
 *Controller
 * @package Bic
 * @author Bic
 * @version $Id: BicSqli.php 2010年5月11日 21时32分29秒
 * @copyright (c) 2010 Bic
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
 * Minimum Requirement: PHP 5.0.1
 */
abstract class Bic_Controller_Abstract extends Bic_Base {
    /**
     *是否自动加载request http
     * @var bool
     */
    public $_autoLoadHttp = false;
    
    public $_helpers = array();
    public $_models = array();

    public function view(){
        /**
         * 初始化模板引擎
         */
        return  Bic_View::getInstance();
    }

    function  __construct() {
        $this -> preController();
        $this->view = $view = $this->view();
        if ($this->_autoLoadHttp){
            $this->http = Bic_Controller_Request_Http::getInstance();
        }
        foreach ($this->_helpers as $help){
            $help = strtolower($help);
            $helpClassName = "Bic_View_Helper_".ucfirst($help);
            $viewHelpName = "{$help}Helper";
            $this->{$viewHelpName} = new $helpClassName();
            $view -> assign($viewHelpName,$this->{$viewHelpName});
        }
        //自动加载Model
        foreach ($this->_models as $model){
            $this->{$model} = App::loadModel(strtolower($model));
        }
    }
    
    /**
     *获取request http
     * @return type 
     */
    protected function getRequest(){
        if ($this->http){
            return $this->http;
        }
        return Bic_Controller_Request_Http::getInstance();
    }


    /**
     *加载Model模块函数
     * @param type $modelName
     * @return \Bic_Model_Abstract
     */
    public function loadModel($modelName){
        return App::loadModel($modelName);
    }
    
    public function preController(){}
    
    public function afterController(){}
}

?>